﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HttpClientStudy.Core
{
    /// <summary>
    /// 默认处理器1 - 添加自定义请求头
    /// </summary>
    public class CustomHeadersHandler : DelegatingHandler
    {
        protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            // 在请求中添加自定义头部
            request.Headers.Add("X-Custom-Header", "CustomValue");

            // 调用管道中的下一个处理器
            return await base.SendAsync(request, cancellationToken);

            //响应信息(可不处理)
        }
    }
}
